from django.db import models

class Product(models.Model):
    product_id = models.IntegerField(primary_key=True, blank=True, db_comment='产品ID')
    product_name = models.CharField(max_length=255, blank=True, null=True, db_comment='产品名称')
    version = models.CharField(max_length=255, blank=True, null=True, db_comment='版本号')
    description = models.CharField(max_length=255, blank=True, null=True, db_comment='描述')
    creation_date = models.DateField(blank=True, null=True, db_comment='创建日期')
    status = models.IntegerField(blank=True, null=True, db_comment='状态')

    class Meta:
        db_table = 'product'


class ProductFormula(models.Model):
    id = models.AutoField(primary_key=True)
    product = models.ForeignKey(to='Product',
                                      on_delete=models.CASCADE,
                                      related_name='formula',
                                      db_comment='产品ID',
                                      db_index=True,)
    material_id = models.IntegerField(blank=True, null=True, db_comment='原料ID')
    material_name = models.CharField(max_length=255, blank=True, null=True, db_comment='原料名称')
    quantity_required = models.IntegerField(blank=True, null=True, db_comment='所需数量')

    class Meta:
        db_table = 'product_formula'